import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// 根据环境变量设置后端地址
const backendUrl = process.env.VITE_BACKEND_URL || 'http://localhost:5000'

export default defineConfig({
  plugins: [vue()],
  server: {
    host: '::',
    port: 5173,
    strictPort: true,
    allowedHosts: [
      'especial.top',
      'localhost',
      '127.0.0.1',
      '::1'
    ],
    proxy: {
      '/api': {
        target: backendUrl,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '/api')
      }
    }
  },
  build: {
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true
      }
    }
  },
  preview: {
    host: '::',
    port: 4173,
    strictPort: true,
    allowedHosts: [
      'especial.top',
      'localhost',
      '127.0.0.1',
      '::1'
    ]
  }
})